package com.cybertron.ironhide.manage.action;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;

import com.cybertron.ironhide.manage.common.base.BaseAction;
import com.cybertron.ironhide.manage.domain.Product;
import com.cybertron.ironhide.manage.service.ProductService;

public class ProductAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7573852308137449959L;

	@Resource
	private ProductService productService;

	private Product product;

	private List<Product> products;

	public String list() throws IOException {
		products = productService.selectBySelective(product, pager);
		return LIST;
	}

	public String index() throws IOException {
		productService.updateIndex();
		return ajaxSuccess("索引更新成功");
	}

	public String delete() {
		productService.deleteByPrimaryKey(product.getId());
		return ajaxSuccess("删除成功", "product-list", null);
	}

	public String edit() {
		product = productService.selectByPrimaryKey(product.getId());
		return EDIT;
	}

	public String doEdit() {
		productService.updateByPrimaryKeySelective(product);
		return ajaxSuccess("更新成功", "product-list", null, CLOSE_CURRENT);

	}

	public String deleteIndex() {
		productService.deleteIndex();
		return ajaxSuccess("删除成功");
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public List<Product> getProducts() {
		return products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

}
